package oop.core.skill;

/**
 * Skill supertype that can't be instantiated.
 * Contains a UNIQUE name and a corresponding skillLevel
 */
public abstract class Skill implements Cloneable{
	protected String name;
	protected int skillLevel;
	
	/**
	 * Skill constructor.
	 * @param name
	 * @param skillLevel
	 */
	protected Skill(String name, int skillLevel){
		this.name = name;
		this.skillLevel = skillLevel;
	}
	
	/**
	 * Increases the skillLevel by 1.
	 */
	public void levelUp(){
		++this.skillLevel;
	}
	
	/**
	 * Increases the skillLevel by levelUpAmount.
	 * @param levelUpAmount
	 */
	public void levelUp(int levelUpAmount){
		this.skillLevel += levelUpAmount;
	}
	
	/** 
	 * get/set methods
	 */
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getSkillLevel() {
		return skillLevel;
	}

	public void setSkillLevel(int skillLevel) {
		this.skillLevel = skillLevel;
	}
	
	/**
	 * Implementing clone.
	 */
	public Skill clone(){
		try{
		      Skill cloned = (Skill)super.clone();
		      return cloned;
	    }catch(CloneNotSupportedException e){
		      System.out.println(e);
		      return null;
	    }
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + skillLevel;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Skill other = (Skill) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (skillLevel != other.skillLevel)
			return false;
		return true;
	}
}
